#include <iostream>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
using namespace std;

void handler(int signo)
{
    pid_t id;
    while (id = waitpid(0,nullptr,WNOHANG))
    {
        if(id<=0)break;
        cout<<"回收进程: "<<id<<endl;
    }
}

int main()
{
    //signal(17, handler);
    signal(SIGCHLD,SIG_IGN); //Linux 自动回收进程

    for(int i=0;i<10;i++)
    {
        pid_t id = fork();
        if(id==0)
        {
            cout<<"child running,pid: "<<getpid()<<endl;
            sleep(7);
            exit(1);
        }
    
        sleep(1);
    }

    while(1)
   sleep(1);
}
